package com.yimi.appstore.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;

public abstract class ExpandableAdapter<T> extends BaseExpandableListAdapter {

	protected Context context;
	protected List<T> listData;
	protected LayoutInflater lInflater;

	public ExpandableAdapter(Context context, List<T> listData) {
		this.context = context;
		this.listData = listData;
		this.lInflater = LayoutInflater.from(context);
	}

	/**
	 * 更新适配器数据
	 * 
	 * @param listData
	 */
	public void updateListData(List<T> listData) {
		this.listData = listData;
		this.notifyDataSetChanged();
	}

	/**
	 * 获取适配器数据
	 * 
	 * @return
	 */
	public List<T> getListData() {
		return this.listData;
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		return null;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public abstract View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
			ViewGroup parent);

	@Override
	public int getChildrenCount(int groupPosition) {
		return 1;
	}

	@Override
	public Object getGroup(int groupPosition) {
		return listData.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		return listData.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	public abstract View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent);

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		return true;
	}

}